'''
https://www.nowcoder.com/practice/e391767d80d942d29e6095a935a5b96b
'''

from functools import cache

s = input()
# s = '(])])([]'
# s = '([[])'
n = len(s)
INF = (2 << 31) - 1


@cache
def f(i, j):
    if i == j: return 1
    if i + 1 == j:
        return 0 if (s[i] == '(' and s[j] == ')') or (s[i] == '[' and s[j] == ']') else 2
    res = INF
    if (s[i] == '(' and s[j] == ')') or (s[i] == '[' and s[j] == ']'):
        res = min(res, f(i + 1, j - 1))
    for m in range(i, j):
        res = min(res, f(i, m) + f(m + 1, j))
    return res


def g():
    dp = [[0] * n for _ in range(n)]
    dp[-1][-1] = 1
    for i in range(n - 1):
        dp[i][i] = 1
        dp[i][i + 1] = 0 if (s[i] == '(' and s[i + 1] == ')') or (s[i] == '[' and s[i + 1] == ']') else 2
    for i in range(n - 3, -1, -1):
        for j in range(i + 2, n):
            res = INF
            if (s[i] == '(' and s[j] == ')') or (s[i] == '[' and s[j] == ']'):
                res = min(res, dp[i + 1][j - 1])
            for m in range(i, j):
                res = min(res, dp[i][m] + dp[m + 1][j])
            dp[i][j] = res
    return dp[0][-1]


# print(f(0, n - 1))
print(g())
